package com.kelvin.paopao.widgets;

import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;

import com.kelvin.paopao.R;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by MCK on 2017/5/11.
 */

public class SelectPayWayView extends LinearLayout {

    /**
     * 0是余额，1是微信
     */
    private int pay_way = 1;

    @BindView(R.id.iv_selected_wallet)
    ImageView ivSelectedWallet;
    @BindView(R.id.iv_selected_wechat)
    ImageView ivSelectedWechat;

    public SelectPayWayView(Context context) {
        super(context);
        init(context, null);
    }

    public SelectPayWayView(Context context, AttributeSet attrs) {
        super(context, attrs);
        init(context, attrs);
    }

    private void init(Context context, AttributeSet attrs) {
        View.inflate(getContext(), R.layout.view_select_pay_way, this);
        ButterKnife.bind(this);
    }

    @OnClick({R.id.ll_pay_wallet, R.id.ll_pay_wechat})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.ll_pay_wallet:
                selectedWallet();
                break;
            case R.id.ll_pay_wechat:
                selectedWechat();
                break;
        }
    }

    /**
     * 使用微信
     */
    private void selectedWechat() {
        pay_way = 1;
        ivSelectedWechat.setImageResource(R.drawable.icon_selected);
        ivSelectedWallet.setImageResource(R.drawable.icon_unselected);
    }

    /**
     * 使用余额
     */
    private void selectedWallet() {
        pay_way = 0;
        ivSelectedWechat.setImageResource(R.drawable.icon_unselected);
        ivSelectedWallet.setImageResource(R.drawable.icon_selected);
    }

    /**
     * 获取选择的支付方式
     *
     * @return
     */
    public int getSelectedWay() {
        return pay_way;
    }
}
